<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>报废设备数据管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//设置当前层级
			if('${nowLevel}' != ""){
				$("#nowLevel").html("[" + "${nowLevel}" + "]");
			}
			
			$("#all").click(function() {
				if (this.checked) {
					$("#check :checkbox").prop("checked", true);
				} else {
					$("#check :checkbox").prop("checked", false);
				}
			});
			$(".checktr").click(function(e){  
			    var check = $(this).find("input[type='checkbox']");  
			    if(check){  
			        var flag = check[0].checked;  
			        if(flag){  
			            check[0].checked = false;  
			        }else{  
			            check[0].checked = true;  
			        }  
			    }  
			});   
			
		});
	
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        
        function Add(){
			openWindowsH400("${ctx}/ccscrapdata/scrapData/addScrapData","",800,450);
		}
		
		function Edit(){
			var count = $("#check").find(":checked").length;
			if(count > 1 ||count < 1){
				/* $.jBox.alert("无法确定对应设备信息，请选择一条设备信息！");
				return false; */
				if(confirm('无法确定对应设备信息，请选择一条设备信息！'))
					return false; 
				return false; 
			}
			//else{
				$("#check").find(":checkbox").each(function(){
					
	              	if($(this).is(":checked")){
					//获取后面td 的内容即 id
						var tr = $(this).closest("tr");
						var E_ID = tr.find("td:eq(1)").text();

						//根据时间判断是否修改
						//var Date = tr.find("td:eq(4)").text();
						var unit = tr.find("td:eq(5)").text();
						if($.trim(unit)){//不为空
							//location.reload(); //刷新当前页面
							alert("设备已经完成报废，无法进行修改！");
							return false;
						}
					 	openWindowsH400("${ctx}/ccscrapdata/scrapData/editScrapData?EQUIPMENT_ID="+E_ID,"修改设备报废信息",800,450);
					 	}  	
	            });
            }
            
		function openWindowsH400(url, title, w, h) {
			w = isNull(w) ? 800 : w;
			h = isNull(h) ? 450 : h;
			var ww = ($(document).width() < w ? $(document).width() - 30 : w)
					+ "px";
			var hh = ($(document).height() < h ? $(document).height() - 30 : h)
					+ "px";
			layer.open({
				type : 2,
				area : [ ww, hh ],
				title : isNull(title) ? "添加设备报废信息" : title,
				fix : false, //不固定
				maxmin : false,
				shade : 0.3,
				shift : 0, //0-6的动画形式，-1不开启
				content : url,
			});
		}
		
		function closeTree(){
			var openCloseDiv = document.getElementById('openClose'); 
			openCloseDiv.click();
		}
		
	</script>
	<style type="text/css">
		.active{
			color: #000000;
		}
		body{
			color: #000000;
		}
		#btnAdd{
			width: 55px;
		}
		#btnChange{
			width: 55px;
		}
		#btnDelete{
			width: 55px;
		}
		#officeContent{
			border: none;
		}
		#nowLevel{
			color: #000;
		}
	</style>
</head>
<body>
	<div id="content" class="row-fluid">
		<div id="left">
			<div class="accordion-heading">
				<a class="accordion-toggle">组织树
					<i id="colseBtn" class="icon-remove pull-right" onclick="closeTree();"></i>
					<label id="nowLevel"></label>
				</a>
			</div>
			<iframe id="officeContent" src="${ctx}/cchierarchy/hierarchy/list" width="100%" height="95%" frameborder="0"></iframe>
		</div>
		<div id="openClose" class="close">&nbsp;</div>
		<div id="right">
			<ul class="nav nav-tabs">
				<li class="active"><a href="${ctx}/ccscrapdata/scrapData/">设备报废管理</a></li>
				<shiro:hasPermission name="ccscrapdata:scrapData:edit"><li><a href="${ctx}/ccscrapdata/scrapData/form">报废设备数据添加</a></li></shiro:hasPermission>
			</ul>
			<form:form id="searchForm" modelAttribute="scrapData" action="${ctx}/ccscrapdata/scrapData/" method="post" class="breadcrumb form-search">
				<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
				<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
				<ul class="ul-form">
					<li style="margin-top: 2px;">设备名称</li>
					<li style="margin-left: 15px;">
						<form:input path="name" htmlEscape="false" maxlength="255" class="input-medium"/>
					</li>
					
					<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" style="margin-left:15px; margin-top: -2px;"/></li>
					<li class="btns"><input type="button" id="btnAdd" class="btn btn-primary" onclick="Add()" value="新增" style="margin-left: 5px; margin-top: -2px;" /></li>
					<li class="btns"><input type="button" id="btnChange" class="btn btn-primary" onclick="Edit()" value="修改" style="margin-left: 5px; margin-top: -2px;" /></li>
					<!-- <li class="btns"><input type="button" id="btnDelete" class="btn btn-primary" onclick="Delete()" value="删除" style="margin-left: 5px; margin-top: -2px;" /></li> -->
					<li class="clearfix"></li>
				</ul>
			</form:form>
			<sys:message content="${message}"/>
			<table id="contentTable" class="table table-striped table-bordered table-condensed">
				<thead>
					<tr  style="width:200px; height:35px;">	
						<th><input id="all" type="checkbox"></th>
						<th>设备编号</th>
						<!-- <th>设备名称</th> -->
						<th>设备</th>
						<th>报废原因</th>
						<th>报废日期</th>
						<th>报废批准单位</th>
						<th>创建者</th>
						<th>创建时间</th>
						<th>修改者</th>
						<th>修改时间</th>
						<shiro:hasPermission name="ccscrapdata:scrapData:edit"><th>操作</th></shiro:hasPermission>
					</tr>
				</thead>
				<tbody id="check">
				<c:forEach items="${page.list}" var="scrapData">
					<!-- <tr style="width:200px; height:35px;"> -->
					<tr data-id="equipmentId" class = "checktr" style="width:200px; height:35px;">
						<td style="width: 10px; "><span><input type="checkbox" id="${scrapData.id}"></span></td>
							
						<td>
							${scrapData.equipmentId}
						</td>
						<td>
							${scrapData.name}
						</td>
						<td>
							${scrapData.cause}
						</td>
						<td>
							<fmt:formatDate value="${scrapData.scrapDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<td>
							${scrapData.ratifyUnit}
						</td>
						<td>
						<!-- id 显示为名称，和user表关联查询 -->
							<%-- ${scrapData.createBy.id} --%>
							${scrapData.createBy.loginName}
						</td>
						<td>
							<fmt:formatDate value="${scrapData.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<td>
						<!-- id 显示为名称，和user表关联查询 -->
							<%-- ${scrapData.updateBy.id} --%>
							${scrapData.updateBy.loginName}
						</td>
						<td>
							<fmt:formatDate value="${scrapData.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<shiro:hasPermission name="ccscrapdata:scrapData:edit"><td>
		    				<a href="${ctx}/ccscrapdata/scrapData/form?id=${scrapData.id}">修改</a>
							<a href="${ctx}/ccscrapdata/scrapData/delete?id=${scrapData.id}" onclick="return confirmx('确认要删除该报废设备数据吗？', this.href)">删除</a>
						</td></shiro:hasPermission>
					</tr>
				</c:forEach>
				</tbody>
			</table>
			<div class="pagination">${page}</div>
		</div>
	</div>	
	
	<script type="text/javascript">
	   		
		var leftWidth = "350"; // 左侧窗口大小
		var htmlObj = $("html"), mainObj = $("#main");
		var frameObj = $("#left, #openClose, #right, #right iframe");
		function wSize(){
			var strs = getWindowSize().toString().split(",");
			/* htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"}); */
			mainObj.css("width","auto");
			frameObj.height(strs[0] - 5);
			var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
			$("#right").width($("#content").width()- leftWidth - $("#openClose").width() -5);
			$(".ztree").width(leftWidth - 10).height(frameObj.height() - 46);
		}
	</script>
	<script src="${ctxStatic}/common/wsize.min.js" type="text/javascript"></script>
	
</body>
</html>